/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-06-03
 * Time: 23:00
 */
public class BubbleSort {

    public static void main(String[] args) {
        int[] array = {1,4,2,9,6,7};
        bubbleSort(array);
        for(int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
    }

    private static void bubbleSort(int[] array) {
        for(int i = 0; i < array.length-1; i++) {
            boolean flag = false;
            for(int j = 0; j < array.length-1-i;j++) {
                if(array[j+1] < array[j]) {
                    swap(array,j,j+1);
                    flag = true;
                }
            }
            if(flag == false) {
                break;
            }
        }
    }

    public static void swap(int[] array,int i,int j) {
        int tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
    }
}
